<?php
class GuestBook_IndexController extends Crb_Controller
{
	
   public function preDispatch()
   {
        parent::preDispatch();
        $this->view->Title = 'Гостевая книга';
   }
    
   public function indexAction()
    {
        $News = new GuestBook();
        $this->view->News = $News->getApprovedList();
        $this->view->page = $this->_getParam('page');
        
        if ($this->getRequest()->isPost())
        {
            $name = $this->_getParam('name');
            $text = strip_tags($this->_getParam('text'));
            $email = strip_tags($this->_getParam('email'));
            $date = strip_tags($this->_getParam('date',''));
            
            $id = $News->add($name, $email, $text);
            
            if (!empty($date))
            {
                $News->setDate($id, $date);
            }
            $this->view->Message = "Спасибо!<br />Ваше сообщение появится немного позже.";
        }
        
        $this->view->headScript()->appendFile('/stuff/jquery/jquery.validate.js');
        
        
    }

    public function viewAction()
    {
        $ID = $this->_request->getParam('id',0);
        $News = new News();
        $oneNews = $News->getOne($ID);
        $this->view->Row = $oneNews; 
        $this->view->Title = $oneNews['Title']; 
    }
}